fix: resolve profile-installed plugins from cordis-plugin-loader - #83
Open
yaojin3616 wants to merge 1 commit into
Open
fix: resolve profile-installed plugins from cordis-plugin-loader#83yaojin3616 wants to merge 1 commit into
yaojin3616 wants to merge 1 commit into
Conversation
Plugins installed via the plugin market (dsh-market) go into the profile's node_modules (e.g. DSH_HOME/profiles/web/node_modules), but the cordis-plugin-loader resolves packages from the app bundle's own node_modules directory. After packaging, these two paths are different, so both hot-mount and post-restart plugin loading fail with 'Cannot find package' errors. This change injects the profile's node_modules directories into the harness Node.js process via two mechanisms: 1. NODE_PATH + Module.globalPaths for CommonJS resolution 2. A custom ESM resolve hook (registered via --import) that falls back to profile node_modules when the default resolution fails The ESM hook uses a synthetic parent URL inside each profile's node_modules directory so that Node's standard resolver (including package.json exports, conditions, subpaths) handles the actual resolution correctly. Closes #73
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #73
Root cause
Plugins installed via the plugin market go into the profile's
node_modules(e.g.DSH_HOME/profiles/web/node_modules), but thecordis-plugin-loaderresolves packages from the app bundle's ownnode_modulesdirectory. After Electron packaging, these two paths are different, so both hot-mount and post-restart plugin loading fail withCannot find packageerrors.The key error from user logs:
Fix
Injects the profile's
node_modulesdirectories into the harness Node.js process via two mechanisms:NODE_PATHand appends toModule.globalPaths--import) that falls back to profilenode_moduleswhen default resolution failsThe ESM hook uses a synthetic parent URL inside each profile's
node_modulesdirectory so that Node's standard resolver — includingpackage.jsonexports, conditions, and subpaths — handles the actual resolution correctly.Files changed
build/profile-module-paths.mjs— Setup script: collects profilenode_modulesdirs fromDSH_HOME, configures CJS paths, registers ESM hookbuild/profile-esm-resolver.mjs— ESM resolve hook with synthetic parent URL fallbacksrc/main/runtime/harness-runtime.ts— Passes--importflag andDSH_DESKTOP_PROFILE_MODULE_PATHSenv to harness processsrc/main/index.ts— Wires profile module paths resource into HarnessRuntimepackage.json— Adds new build files toextraResourcestest/runtime.test.ts— Updated tests for new argumentstest/profile-module-paths.test.ts— Tests for ESM resolver behavior